import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { RecordLoginEntity } from './entities/record_login.entity';
import { Repository } from 'typeorm';
import { CreateRecordLoginDto } from './dto/create-record_login.dto';
// import { UpdateRecordLoginDto } from './dto/update-record_login.dto';

@Injectable()
export class RecordLoginService {
  constructor(
    @InjectRepository(RecordLoginEntity)
    private readonly recordLoginRepository: Repository<RecordLoginEntity>,
  ) {}
  create(createRecordLoginDto: CreateRecordLoginDto) {
    return this.recordLoginRepository.save(createRecordLoginDto);
  }

  async findAll() {
    const qb = this.recordLoginRepository.createQueryBuilder();
    qb.orderBy('login_time', 'DESC');
    return await qb.getMany();
  }

  async findOne(id: string) {
    return await this.recordLoginRepository.findOne({ where: { user_id: id } });
  }

  // update(id: number, updateRecordLoginDto: UpdateRecordLoginDto) {
  //   return `This action updates a #${id} recordLogin`;
  // }

  // remove(id: number) {
  //   return `This action removes a #${id} recordLogin`;
  // }
}
